package com.kamistoat.meimeimall.meimeimallmember.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class MemberThreadConfig {
    /**
     * 用于生成测试数据并执行批量插入。
     * 由于不是单纯的执行数据库插入，还包括生成收货地址测试数据。压测时发现按照每个线程处理100000条数据，最大线程数超过8会压爆内存。
     */
    @Bean("flushMemberTestDataThreadPoolExecutor")
    public ThreadPoolExecutor flushMemberTestDataThreadPoolExecutor() {
        return new ThreadPoolExecutor(
                4,
                8,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(8),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
